<?php

class sfWidgetFormFileupload extends sfWidgetFormInputFile
{
    /**
     * Configures the current widget.
     *
     * @param array $options     An array of options
     * @param array $attributes  An array of default HTML attributes
     *
     * @see sfWidgetForm
     */
    protected function configure($options = array(), $attributes = array())
    {
      parent::configure($options, $attributes);
      $this->addRequiredOption('file_src');
      $this->setAttribute('class', 'fileupload');
      $this->setAttribute('data-provides', 'fileupload');
    }

    /**
     * Renders the widget.
     *
     * @param  string $name        The element name
     * @param  string $value       The value displayed in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
      return    '<div class="fileupload fileupload-'.($this->getOption('file_src') == false ? 'new':'exists').'" data-provides="fileupload">
		        	<div class="fileupload-preview fileupload-medium thumbnail">
		        	    <img src="'.$this->getOption('file_src').'">
		        	</div>
		        	<div>
		        		<span class="btn btn-file">
		        			<span class="fileupload-new">Зураг сонго</span>
		        			<span class="fileupload-exists">Солих</span>
		        			'.parent::render($name, $value, $attributes, $errors).'
		        		</span>
		        		<!--<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Устгах</a>-->
		        	</div>
		        </div>';
    }

    public function getJavaScripts()
    {
        return array(
            "/js/bootstrap/bootstrap-fileupload.js",
            "/js/bootstrap/bootstrap-inputmask.js"
        );
    }

}
